home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / uart < prev    next >
Text File  |  1995-03-31  |  9KB  |  299 lines

  1. Article 5921 of comp.sys.handhelds:
  2. Path: en.ecn.purdue.edu!noose.ecn.purdue.edu!samsung!think.com!snorkelwacker.mit.edu!ai-lab!rice-chex!bson
  3. From: bson@rice-chex.ai.mit.edu (Jan Brittenson)
  4. Newsgroups: comp.sys.handhelds
  5. Subject: The HP-48 UART - Basic Usage
  6. Message-ID: <14901@life.ai.mit.edu>
  7. Date: 15 Apr 91 02:24:49 GMT
  8. Sender: news@ai.mit.edu
  9. Organization: nil
  10. Lines: 285
  11.  
  12.  
  13.    I hope the following brief and basic explanation will prove useful
  14. to anyone interested in using the HP-48 UART for serial wire
  15. communication from ML programs. Please e-mail me if you find any
  16. inconsistencies in it.
  17.  
  18.    This draft, is dated April 14, 1991. Do whatever you wish with it -
  19. publication, printing, and other forms of mass distribution highly
  20. encouraged.
  21.  
  22.                         -- Jan Brittenson
  23.                            bson@ai.mit.edu
  24.  
  25.  O  /
  26.   \/
  27.   /\  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  28.  O  \
  29.  
  30.  
  31. INRODUCTION
  32. -----------
  33.  
  34.    The HP-48 UART (Universal Asynchronous Receiver-Transmitter) is
  35. capable of simultaneously sending and receiving data at speeds of
  36. 1200, 2400, 4800 and 9600 bps (bits per second). This document deals
  37. not with how to communicate from a user or system RPL program, but how
  38. to do so from ML (Machine Language). Only the basics are covered:
  39.  
  40.     o I/O registers and system data
  41.  
  42.     o ML routines
  43.  
  44.     o About communication
  45.  
  46.     o Sample program
  47.  
  48.  
  49.  
  50. HP-48 UART REGISTERS
  51. --------------------
  52.  
  53.    The list below describes the registers and memory locations
  54. relevant to the basic UART operation. Each entry consists of a header:
  55.  
  56.     name.size    #address/access
  57.  
  58.    The name is a symbolic name. The size is the size rounded up to an
  59. integral nybble. The address is the memory location in a default
  60. system configuration. The access specifices whether the register or
  61. location can read from, written into, or both.
  62.  
  63.  
  64.  
  65.     XMIT.2        #00116/write
  66.  
  67.        UART transmitter register. Writing a character to this
  68.     address causes it to be transmitted serially. Make sure the
  69.     transmitter is finished with the previous character before
  70.     writing.
  71.  
  72.  
  73.     RECV.2        #00114/read
  74.  
  75.        UART receiver register. The most recently received
  76.     character can be found here. Must be read before the next
  77.     character has been received.
  78.  
  79.  
  80.     RECVBUF.256    #701FC/read-write
  81.  
  82.        256-character serial receive buffer. Data is automatically
  83.     added to the buffer via interrupts into system code as they
  84.     arrive in the UART receiver.
  85.  
  86.  
  87.     RECVHEAD.8    #703FC/read-write
  88.  
  89.        8-nybble serial buffer head. Contains size, get, and put
  90.     counters. Use the ML routine at #31289 (see below) to
  91.     obtain the next character.
  92.  
  93.  
  94.     USTAT.1        #00112/read
  95.  
  96.     -------------
  97.     |  |  |RR|XR|    XR: XMIT ready
  98.     -------------    RR: RECV ready
  99.       3  2  1  0
  100.  
  101.        XR is set if XMIT is ready to accept another character,
  102.     otherwise it is cleared. RR is set when a character is
  103.     available in the UART RECV register. Do not alter bits 3 and
  104.     2.
  105.  
  106.  
  107.     PACING.1    #70401/read-write
  108.  
  109.     -------------
  110.     |XH|  |RH|RF|    XH: XMIT handshaking recognized
  111.     -------------    RH: RECV handshaking used
  112.       3  2  1  0    RF: XOFF transmitted
  113.  
  114.           Bits 0 and 2 must not be modified, as they are RAM shadows
  115.     for location #0011A. Handshaking on the HP-48 is implemented
  116.     in software. The RF bit signals that the RECV system interrupt
  117.     routine has sent an XOFF to XMIT.
  118.  
  119.  
  120.     PACRQ.1        #70402/read-write
  121.  
  122.     -------------
  123.     |RF|  |  |  |    RF: XOFF transmission requested
  124.     -------------
  125.       3  2  1  0
  126.  
  127.        The RF bit is set when RECVBUF is almost filled up but XMIT
  128.     is busy. This bit should be checked before a character is
  129.     transmitted.
  130.  
  131.  
  132.     PARITY.1    #70403/read-write
  133.  
  134.     -------------    PE: Parity enable, 0 = None
  135.     |PE|P2|P1|P0|    
  136.     -------------    P2 P1 P0
  137.       3  2  1  0     1  0  0    Even 2
  138.              1  0  1    Odd 1
  139.              1  1  0    Spc 4
  140.              1  1  1    Mark 3
  141.  
  142.        P0-P2 must all be zero if no parity is used. Parity is
  143.     implemented in software on the HP-48, and is resolved before
  144.     characters are added to RECVBUF (see above). For transmission,
  145.     the ML routine at #3113D (see below) can be used to adjust
  146.     bits 0-7 of register A according to the current parity
  147.     setting.
  148.  
  149.  
  150.     BPS.3        #0010D/read-write
  151.  
  152.        11-bit register specifying the current serial transmission
  153.     speed.
  154.  
  155.         Value    Speed, BPS
  156.  
  157.          #600      9600
  158.          #400      4800
  159.          #200      2400
  160.          #000      1200
  161.  
  162.        Bit 3 of #10E is used for other purposes, and care must be
  163.     taken not to alter it. Both receiver and transmitter operate
  164.     at the same speed.
  165.  
  166.  
  167.     UINTR.1        #00110/read-write
  168.  
  169.     -------------    RI: RECV interrupt
  170.     |RI|RE|XI|XE|    RE: RECV interrupt enable
  171.     -------------    XI: XMIT interrupt
  172.       3  2  1  0    XE: XMIT interrupt enable
  173.  
  174.        UART interrupt register. The RE bit enables RECV
  175.     interrupts, which are triggered when a character becomes
  176.     available in the RECV register. XE enables XMIT empty
  177.     interrupts, which are triggered whenever XMIT is ready for a
  178.     new character. The RI and XI bits are set whenever a RECV and
  179.     XMIT interrupt has been triggered. They are checked by the
  180.     system interrupt handler to determine the cause of the
  181.     interrupt.
  182.  
  183.  
  184.  
  185. ROM COMMUNICATION ROUTINES
  186. --------------------------
  187.  
  188.     #310CA    Check if UART XMIT ready for another character.
  189.         Checks bit 0 of USTAT.
  190.  
  191.         Out:
  192.         Carry    Clear if ready
  193.  
  194.  
  195.     #3113D    Add parity to character according to current
  196.         parity setting. Parity of RECV characters can
  197.         be checked by saving the character, calling this
  198.         routine, and then comparing the results. They
  199.         should be equal. All 8 bits are left alone if
  200.         parity is `none.'
  201.  
  202.         In:
  203.         A.B    Character
  204.  
  205.         Out:
  206.         A.B    Character with parity bit in bit 7
  207.  
  208.  
  209.     #31289    Get next character from the serial buffer.
  210.  
  211.         Out:
  212.         A.B    Character
  213.         Carry    Set if buffer is empty
  214.  
  215.  
  216.     #31085    Check if receive buffer is full. That is, if
  217.         there isn't room for one more character.
  218.  
  219.         Out:
  220.         Carry    Set if buffer is full.
  221.  
  222.  
  223.  
  224. COMMUNICATION
  225. -------------
  226.  
  227.    Character reception is done by an interrupt routine. Whenever a
  228. character is ready in the UART RECV register, an interrupt is
  229. triggered, and a call to the commmoninterrupt entry in the ROM is
  230. made. The interrupt handler in ROM looks at the UINTR bits to find the
  231. cause of the interrupt; if it was RI, then a dispatch to the RECV
  232. interrupt handler is made. The RECV handler retrieves the character
  233. and adds it to the buffer. If there are less than 16 characters
  234. available, it attempts to transmit an XOFF, if handshaking (see the
  235. PACING location) is enabled. If the transmitter is busy, it instead
  236. flags an XOFF request in the PACRQ location. Thus, a program
  237. transmitting data has to check this flag before each successive
  238. character is transmitted; if it's set, an XOFF should be transmitted.
  239.  
  240.    No XMIT interrupt handler exists in ROM, and no user handler can be
  241. added. It is debatable whether this is useful for implementing light
  242. sleep between transmitted characters. Or rather, how useful that would
  243. be. I do not know whether the UART is operational in light sleep,
  244. or whether it has the option of remaining so.
  245.  
  246.    In general, it is much more desirable to deal with RECVBUF via the
  247. ROM routines than dealing with the raw operation of the RECV I/O
  248. register. Still, I can conceive of at least one possible instance
  249. where dealing with the RECV register directly is desirable. That is if
  250. the receiver can operate in light sleep, and you don't want to be
  251. woken up from your light sleep by incoming serial data. In such a case
  252. it may be desirable to generally keep RECV interrupts disabled and
  253. employ polling.
  254.  
  255.    There isn't any XOFF detection in the RECV interrupt handler. The
  256. code that does the transmission has to check whether the next
  257. character in RECVBUF is an XOFF. This seems like a flaw to me - the
  258. `MS-DOS XON/XOFF syndrome.' It breaks when XOFF is not the first
  259. character in RECVBUF and further transmission is required before
  260. RECVBUF is cycled through. Instead, the RECV interrupt handler should
  261. have checked for XOFF (if enabled) and a RAM bit used to flag a paused
  262. condition to the transmitting code.
  263.  
  264.  
  265. A SAMPLE PROGRAM
  266. ----------------
  267.  
  268.    The following sample program (STAR syntax) creates a loopback.
  269. Whatever is received in RECVBUF is echoed on XMIT. The program ignores
  270. parity and RECV interrupt handler XOFF requests. Can you think of a
  271. way to add these features?
  272.  
  273.  
  274. getc_srecvbuf_a_p = 0x31289
  275. uart_xmit_rdy_p = 0x310ca
  276. xmit = 0x116
  277.  
  278. echo:
  279.     call    getc_srecvbuf_a_p    ; A.B = RECVBUF character
  280.     brcs    echo            ; RECVBUF empty - loop
  281.     move    a, r0            ; R0.B = character
  282. $100:
  283.     call    uart_xmit_rdy_p        ; XMIT RDY?
  284.     brcs    $100            ; Nope - loop until it is
  285.     move.5    xmit, d0
  286.     move    r0, c
  287.     move.b    c, @d0            ; XMIT = character
  288.  
  289.     jump    echo            ; Echo next character
  290.  
  291.  
  292.  
  293. [This line and the signature below are not part of the document.]
  294.  
  295.                         -- Jan Brittenson
  296.                            bson@ai.mit.edu
  297.  
  298.  
  299.